﻿Ext.override(Ext.form.Field, {

    afterRender: function() {

        if (this.helpText) {
            var el = findFormEl(this);
            if (el) {

                var helpImage = el.createChild({
                    tag: 'img',
                    src: '/images/help.png',
                    style: 'margin-bottom: 0px; margin-left: 5px; padding: 0px;'
                });

                Ext.QuickTips.register({
                    target: helpImage,
                    text: this.helpText,
                    enabled: true
                });

            }
        }
        if (this.allowBlank == false) {
            var label = findLabel(this);
            if (label) {
                label.dom.innerHTML = label.dom.innerHTML.replace(':', '<span class="x-form-field-asterisk">*</span>:');
            }
        }

        Ext.form.Field.superclass.afterRender.call(this);
        this.initEvents();
    }
});

var findFormEl = function(field) {
    var wrapDiv = null;
    var el = null

    //find form-item and label
    wrapDiv = field.getEl().up('div.x-form-item');
    if (wrapDiv) {
        el = wrapDiv.child('div.x-form-element');
    }
    if (el) {
        return el;
    }
}

var findLabel = function(field) {
    var wrapDiv = null;
    var label = null

    //find form-item and label
    wrapDiv = field.getEl().up('div.x-form-item');
    if (wrapDiv) {
        label = wrapDiv.child('label');
    }
    if (label) {
        return label;
    }
}